MAKE                =	make
CC                  =	g++
INCPATH             =   ../../../include
LIB_DIR             =   ../../../lib/linux/
BIN_DIR             =   ../../../bin/linux/
GTLOG_LIB_DIR       =   ../../../tools/gtlog/lib/Linux/
GTLOG_INCLUDE_DIR   =   ../../../tools/gtlog/include/
LOG_LIB_DIR         =   ../../../tools/log/lib/linux/
LOG_INCLUDE_DIR     =   ../../../tools/log/include/
CLIENT_EXE          =   cppTutorTCPClient
SERVER_EXE          =   cppTutorTCPServer
CLIENT_LIB_STA	    =   libcppTutorTCPClient.a
CLIENT_LIB_DYA      =   libcppTutorTCPClient.so
SERVER_LIB_STA	    =   libcppTutorTCPServer.a
SERVER_LIB_DYA      =   libcppTutorTCPServer.so
STATIC_LOG          =   lcppTutorLog
GTLOG               =   lgtlog
SRCS                =   $(shell ls *.cpp)
SRCS_C              =   $(shell ls *.c)
SOCKET_OBJS         =   $(subst .cpp,.o,$(SRCS)) ../../cppTutorMain.o ../../cppTutorLog.o
TCPSERVEROBJ	    =	cppTutorTCPSocketServer.o
TCPCLIENTOBJ	    =	cppTutorTCPSocketClient.o
LINK                =	-g -pedantic -Wall -lstdc++ -lpthread -ldl -lm -$(STATIC_LOG) -$(GTLOG) -Wl,-rpath,.
COMPILE	            =	-g -O0 -D_THREAD_SAFE -pedantic -Wall -c -fPIC -Wno-deprecated
SERVER_OBJS         =   $(TCPSERVEROBJ)
CLIENT_OBJS         =   $(TCPCLIENTOBJ)
OBJS                =   $(subst .cpp,.o,$(SRCS))
OBJS_C              =   $(subst .c,.o,$(SRCS_C))

.SUFFIXES: .o .cpp .c

.cpp.o:
	$(CC) -I $(INCPATH) -I $(LOG_INCLUDE_DIR) -I $(GTLOG_INCLUDE_DIR) $(COMPILE) $<

all: tcpClient tcpServer
#all: tcpClientStatic tcpServerStatic

tcpClient: $(CLIENT_OBJS)
	$(CC) -o $(BIN_DIR)$(CLIENT_EXE) $(CLIENT_OBJS) -L $(LOG_LIB_DIR) -L $(GTLOG_LIB_DIR) -L. $(LINK)

tcpServer: $(SERVER_OBJS)
	$(CC) -o $(BIN_DIR)$(SERVER_EXE) $(SERVER_OBJS) -L $(LOG_LIB_DIR) -L $(GTLOG_LIB_DIR) -L. $(LINK)

-include depend.mak

depend:
	g++ -MM $(SRCS) > depend.mak

shared: $(OBJS)
	$(CC) -shared -Wl,-soname -lc -o $(LIB_DIR)$(SHARED_TEST) $(OBJS) -L.

tcpClientStatic: $(CLIENT_OBJS)
	ar rucvs $(LIB_DIR)$(CLIENT_LIB_STA) $(CLIENT_OBJS)

tcpServerStatic: $(SERVER_OBJS)
	ar rucvs $(LIB_DIR)$(SERVER_LIB_STA) $(SERVER_OBJS)

clean:
	rm -rf $(OBJS) depend.mak $(BIN_DIR)$(SERVER_EXE) $(BIN_DIR)$(CLIENT_EXE) $(LIB_DIR)*

cleanapp:
	rm -rf $(BIN_DIR)$(SERVER_EXE) $(BIN_DIR)$(CLIENT_EXE) $(LIB_DIR)*
